<?php
/* [DoYouHaoBaby!] (C)Dianniu From 2010.
   this($)*/

!defined('DYHB_PATH') && exit;

class TemplateGtkGladeWidgetCompiler_GtkComboBox extends TemplateGtkGladeWidgetCompiler_GtkContainer{

	protected function compileCreateWidget_(TemplateGtkGladeWidget $oObject, $bCreateCellRenderAndActive=true){
		$sWidgetClass=$oObject->getWidgetClass();
		$sVariableName='$'.TemplateGtkGlade::getWidgetVariableName($oObject);
		$sCompiled="\t\t{$sVariableName}=new {$sWidgetClass}();";// 创建窗体对象
		// 初始化
		$sCompiled.="
		\$oListStore=new GtkListStore(Gtk_TYPE_STRING);
		{$sVariableName}->set_model(\$oListStore);
";
		if($bCreateCellRenderAndActive)// 创建 GtkCellRenderer 对象
			$sCompiled.="
		\$oCellRenderer=new GtkCellRendererText();
		{$sVariableName}->pack_start(\$oCellRenderer);
		{$sVariableName}->set_attributes(\$oCellRenderer,'text',0);
";
		// 菜单数据
		if($sItems=$oObject->getProperty('items')){
			$arrItems=explode("\n",str_replace("\r",'',$sItems));
			foreach($arrItems as &$sItem){
				$sCompiled.="\t\t\$oListStore->append(array(\"{$sItem}\"));;";
			}
		}
		if($bCreateCellRenderAndActive and ($sActive=$oObject->getProperty('active'))!==null){// 菜单初始项
			$sCompiled.="\t\tif(\$oListStore->get_n_columns()>{$sActive})";
			$sCompiled.="\t\t\t{$sVariableName}->set_active({$sActive});";
		}
		if(($sWrapWidth=$oObject->getProperty('wrap_width'))!==null){$sCompiled.="\t\t{$sVariableName}->set_wrap_width({$sWrapWidth});";}// 换行宽度
		if(($sValue=$oObject->getProperty('row_span_column'))!==null){$sCompiled.="\t\t{$sVariableName}->set_row_span_column({$sValue});";}// 行跨列
		if(($sValue=$oObject->getProperty('column_span_column'))!==null){$sCompiled.="\t\t{$sVariableName}->set_column_span_column({$sValue});";}// 列跨列
		if(TemplateGtkGladeObj::nodeTextToValue($oObject->getProperty('add_tearoffs'))){$sCompiled.="\t\t{$sVariableName}->set_add_tearoffs(true);";}// 添加撕下标志

		// 撕下标题
		//if(($sValue=$oObject->getProperty('tearoff_title'))!==null)
		// $sCompiled.="\t\t{$sVariableName}->set_column_span_column({$sValue});;";
		// 有无边框
		//if(TemplateGtkGladeObj::nodeTextToValue($oObject->getProperty('has_frame'))===false)
		// $sCompiled.="\t\t{$sVariableName}->set_has_frame(false);";

		// 点击获得焦点
		if(TemplateGtkGladeObj::nodeTextToValue($oObject->getProperty('focus_on_click'))===false){$sCompiled.="\t\t{$sVariableName}->set_focus_on_click(false);";}
		return $sCompiled;
	}

	static public function regToProcessorManager(ITemplateObjProcessorManager $oManager){
		$oManager->regProcessor(str_replace('TemplateGtkGladeWidgetCompiler_','',__CLASS__),__CLASS__);
	}

}
